<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/10 0010
 * Time: 14:42
 */
namespace app\api\controller;
use app\admin\model\ClockModel;
use app\admin\model\CompanyModel;
use app\admin\model\DepartmenModel;
use app\admin\model\LeaveModel;
use app\admin\model\NoticeModel;
use app\admin\model\ReportModel;
use app\admin\model\SettingModel;
use app\admin\model\UserModel;
use app\api\model\Api as Apis;
use app\index\model\GetUser;
use app\index\model\UpFile;
use think\Db;
use think\helper\Time;
use think\Request;

class Index
{
    /**
     * @return \think\response\Json
     */
    public function index(){
        $user = Db::name('user')->select();
        return json(['code'=>200,'data'=>$user]);
    }
    //登录接口
    public function login(Request $request){
        $data = $request->param();
        $val = val($data,[
            'user|账号'=>'require',
            'pwd|密码'=>'require'
        ]);
        if(!$val['code']){
            return returns(403,$val['msg']);
        }
        $user = UserModel::getIndexUser()
            ->where('user.user',$data['user'])
            ->find();
        if($user&&(getPwd($data['pwd'])==$user['pwd'])){
            $number = md5(uniqid().$data['user']);
            if(UserModel::updateIndexUser(['id'=>$user['id'],'token'=>$number])){
                $user['token'] = $number;
                return json(['code'=>200,'msg'=>'登录成功','user'=>$user]);
            }else{
                return returns(403,'服务器忙');
            }

        }else{
            return returns(403,'账号或密码错误');
        }
    }

    /**获取打卡设置
     * @param Request $request
     * @return array
     */
    public function getSetting(Request $request){
        $data = $request->param();
        $val = val($data,[
           'token'=>'require',
            'mac'=>'require'
        ]);
        if(!$val['code']){
            return returns(401,'请登录');
        }
        $user = GetUser::get($data['token']);
        $setting = SettingModel::getSetting()
            ->where('card_setting.department_id',$user['department_id'])
            ->find();
        $work_shift = floor($setting['work_shift']/3600);
        if($work_shift<10){
            $work_shift = '0'.$work_shift;
        }
        $work_shift1 = floor($setting['work_shift']%3600/60);
        if($work_shift1<10){
            $work_shift1 = '0'.$work_shift1;
        }
        $setting['work_shift'] = $work_shift.':'.$work_shift1;
        $closing_time = floor($setting['closing_time']/3600);
        if($closing_time<10){
            $closing_time = '0'.$closing_time;
        }
        $closing_time1 = floor($setting['closing_time']%3600/60);
        if($closing_time1<10){
            $closing_time1 = '0'.$closing_time1;
        }
        $setting['closing_time'] = $closing_time.':'.$closing_time1;
        foreach ($setting['attendance'] as $key=>$value){
            if($value==1){
                $setting['attendance'][$key] = '一';
            }elseif ($value==2){
                $setting['attendance'][$key] = '二';
            }
            elseif ($value==3){
                $setting['attendance'][$key] = '三';
            }
            elseif ($value==4){
                $setting['attendance'][$key] = '四';
            }
            elseif ($value==5){
                $setting['attendance'][$key] = '五';
            }
            elseif ($value==6){
                $setting['attendance'][$key] = '六';
            }
            elseif ($value==0){
                $setting['attendance'][$key] = '天';
            }
        }
        $setting['late_time'] = floor($setting['late_time']/60);
        $setting['overtime'] = floor($setting['overtime']/60);
        if($data['mac']==$setting['mac']){
            return json(['code'=>200,'msg'=>'已连接打卡Wi-Fi','data'=>$user,'setting'=>$setting,'wei'=>Apis::getNews($user['id'])]);
//            return returns(200,'已连接打卡Wi-Fi',$user);
        }else{
            return json(['code'=>201,'msg'=>'未连接打卡Wi-Fi','data'=>$user,'setting'=>$setting,'wei'=>Apis::getNews($user['id'])]);
        }
    }

    /**设置打卡设置
     * @param Request $request
     * @return \think\response\Json
     */
    public function setTheSetting(Request $request){
        $data = $request->param();
        $work_shift = explode(':',$data['work_shift']);
        $data['work_shift'] = (int)$work_shift[0]*3600+(int)$work_shift[1]*60;
        $closing_time = explode(':',$data['closing_time']);
        $data['closing_time'] = (int)$closing_time[0]*3600+(int)$closing_time[1]*60;
        $data['attendance'] = explode('、',trim(trim($data['attendance'],'星期'),'、'));
        $data['late_time']  = trim($data['late_time'],'分')*60;
        $data['overtime']  = trim($data['overtime'],'分')*60;
        $token = $data['token'];
        unset($data['token']);
        $user = GetUser::get($token);
        if(!Apis::AuthIndex('部门打卡设置',$user)){
            return returns(203,'你的额权限不足');
        }
        $data['wifi_ip'] = ip();
        $data['update_time'] = time();
        if(Db::name('card_setting')->where('department_id',$user['department_id'])->update($data)){
            return returns(200,'修改成功');
        }else{
            return returns(202,'修改失败,请稍后再试');
        }
    }

    /**打卡接口
     * @param Request $request
     * @return \think\response\Json
     */
    public function clock(Request $request){
        $data = $request->param();
        $val = val($data,[
            'token'=>'require',
            'type' =>'require',
            'mac'  =>'require'
        ]);
        if(!$val['code']){
            return returns(205,$val['msg']);
        }
        $user = GetUser::get($data['token']);
        $setting = SettingModel::getSetting()
            ->where('card_setting.department_id',$user['department_id'])
            ->find();
        if(!($data['mac']==$setting['mac'])){
            return returns(203,'未连接打卡wifi');
        }
        $type = $request->param('type');
        //组装数据存入打卡记录
        $data['userid'] = $user['id'];
        $data['company_id'] = $user['company_id'];
        $data['departmen_id'] = $user['department_id'];
        $data['punch_type'] = $type;
        $data['create_time'] = time();
        $work = date('w',time());
        //获取今天的开始时间戳和结束时间戳
        list($start,$end) = Time::today();
//        return json(['code'=>203,'start'=>$start,'time'=>time(),'end'=>$end]);
        $jiou = ClockModel::getClock()
            ->where('punch_clock.userid',$user['id'])
            ->where('punch_clock.punch_type',$type)
            ->where('punch_clock.create_time','>',$start)
            ->where('punch_clock.create_time','<',$end)
            ->select();
        if($jiou){
            return json(['code'=>405,'msg'=>'你已经打过这个卡了']);
        }
//        return json(['code'=>201,'msg'=>$jiou]);
        if(!in_array($work,$setting['attendance'])){
            return json(['code'=>999,'msg'=>'今天不上班,请联系你的领导']);
        }
        //打上班卡
        if($type=='toWork'){
            //return json([time(),$start+$setting['late_time']]);
            //迟到
            if(time()>($start+$setting['work_shift'])&&time()<=($start+$setting['work_shift']+$setting['late_time'])){
                $data['late'] = 1;
            }
            //旷工
            if(time()>($start+$setting['work_shift']+$setting['late_time'])){
                $data['absenteeism'] = 1;
            }
        }elseif ($type=='offWork'){
            //早退
            if(time()<($start+$setting['closing_time'])){
                $data['early_retreat'] = 1;
            }
            //加班
            if(time()>($start+$setting['closing_time']+$setting['overtime'])){
                $data['overtime'] = 1;
            }
        }
        unset($data['mac']);
        unset($data['token']);
        unset($data['type']);
        //添加打卡记录
        $bool = ClockModel::addClock($data);
        if($bool){
//            cache($user['id'].$type,'1',($end-time()));
            return json(['code'=>200,'msg'=>'打卡成功']);
        }else{
            return json(['code'=>205,'msg'=>'打卡失败,请等一分钟再试']);
        }
    }

    /**获取公告
     * @param Request $request
     * @return \think\response\Json
     */
    public function getNotice(Request $request){
        $token = $request->param('token',null);
        if(!$user = GetUser::get($token)){
            return returns();
        }
        $data['com'] = NoticeModel::getNotice(false)->where('notice.notice_type',0)->order('notice.creat_time desc')->limit(3)->select();
        $data['dep'] = NoticeModel::getNotice()->where('notice.notice_type',$user['department_id'])->order('notice.creat_time desc')->limit(3)->select();
//        echo '<pre>';
//        print_r($data);exit;
        return json(['code'=>200,'data'=>$data]);
    }
//public function noticeInfo(){
//        return 1;
//}
    /**获取公告详情
     * @param Request $request
     * @return \think\response\Json
     */
    public function getNoticeInfo(Request $request){
        $id = $request->param('id',null);
        $token = $request->param('token',null);
        if(!$user= GetUser::get($token)){
            return returns();
        }
        $data = NoticeModel::getNotice()->where('notice.id',$id)->find();
        if(!$data){
            $data = NoticeModel::getNotice(false)->where('notice.id',$id)->find();
        };
        $zuozhe = UserModel::getIndexUser()
            ->where('user.id',$data['author'])
            ->find();
        $data['readers'] = $data['readers']+1;
        if(NoticeModel::updateNotice(['id'=>$data['id'],'readers'=>$data['readers']])){
            return json(['code'=>200,'data'=>$data,'zuozhe'=>$zuozhe]);
        }else{
            return returns(202,'获取数据失败');
        }
    }

    /**获取公告列表
     * @param Request $request
     * @return \think\response\Json
     */
    public function noticeList(Request $request){
        $data = $request->param();
        if(!$data['token']||!$data['type']){
            return returns(205,'参数有误');
        }
        if(!$user = GetUser::get($data['token'])){
            return returns();
        }
        if($data['type']=='com'){
            $data = NoticeModel::getNotice(false)
                ->where('notice.notice_type',0)
                ->select();
        }elseif ($data['type']=='dep'){
            $data = NoticeModel::getNotice()
                ->where('notice.notice_type',$user['department_id'])
                ->select();
        }else{
            return returns(205,'参数错误');
        }
        foreach ($data as $key=>$value){
            $data[$key]['creat_time'] = date('m-d',$data[$key]['creat_time']);
        }
        return returns(200,'获取成功',$data);
    }

    /**发布公告
     * @param Request $request
     * @return \think\response\Json
     */
    public function newComNotice(Request $request){
        $data = $request->param();
        $val = val($data,[
            'title|标题'=>'require',
            'token'     =>'require',
            'notice_type|类型'=>'require'
        ]);
        if(!$val['code']){
            return returns(205,'参数有误');
        }
        if(!$user = GetUser::get($data['token'])){
            return returns();
        }
        $notice_type = '添加部门公告';
        if($data['notice_type']=='com'){
            $notice_type = '添加公司公告';
            $data['notice_type'] = 0;
        }else{
            $data['notice_type'] = $user['department_id'];
        }
        if(!Apis::AuthIndex($notice_type,$user)){
            return returns(203,'你的权限不足');
        }
        unset($data['token']);
        $data['author'] = $user['id'];
        $data['readers'] = 0;
        $data['affirming'] = $user['departmen_name'].$user['position_name'].'-'.$user['nickname'];
        $data['creat_time'] = time();
        $file = UpFile::getFile($request);
        if($file){
            foreach ($file as $value){
                $data['picture'][] = $value;
            }
        }
        if(NoticeModel::addNotice($data)){
            return returns(200,'添加公告成功');
        }else{
            return returns(200,'添加公告失败');
        }
    }

    /**查看考勤
     * @param Request $request
     * @return \think\response\Json
     */
    public function getCheckWork(Request $request){
        $data = $request->param();
        if(!$data['token']){
            return returns(203,'请登录');
        }
        if(!$data['year']){
            $data['year'] = date("Y",time());
        }
        if(!$data['month']){
            $data['month'] = date("m",time());
        }
        if(!$user = GetUser::get($data['token'])){
            return returns();
        }
        if((int)$data['year']>(int)date('Y',time())){
            return returns(205,$data['year'].'年还没到');
        }
        if(((int)$data['year']==(int)date('Y',time()))&&(int)$data['month']>(int)date('m',time())){
            return returns(205,$data['month'].'月还没到');
        }
        $time = $data['year'].'-'.$data['month'];
        $time = Apis::getDays($user['department_id'],$time);
        $setting = SettingModel::getSetting()
            ->where('card_setting.department_id',$user['department_id'])
            ->find();
        foreach ($time as $value){
            if($value<10){
                $value = '0'.$value;
            }
            $start = strtotime($data['year'].'-'.$data['month'].'-'.$value);
            $end   = $start+24*3600;
            if($end>time()){
                $end = time();
            }
            if(time()<$start+$setting['work_shift']){
                $clock[date('m月d日',$start)]['toWork'] = '未到打卡时间';
            }else{
                $clock[date('m月d日',$start)]['toWork'] = ClockModel::getClock()
                    ->where('punch_clock.punch_type','toWork')
                    ->where('punch_clock.create_time','>',$start)
                    ->where('punch_clock.create_time','<',$end)
                    ->where('punch_clock.userid',$user['id'])
                    ->find();
            }
            if(time()<$start+$setting['closing_time']){
                $clock[date('m月d日',$start)]['offWork'] = '未到打卡时间';
            }else{
                $clock[date('m月d日',$start)]['offWork'] = ClockModel::getClock()
                    ->where('punch_clock.punch_type','offWork')
                    ->where('punch_clock.create_time','>',$start)
                    ->where('punch_clock.create_time','<',$end)
                    ->where('punch_clock.userid',$user['id'])
                    ->find();
            }
        }
//        echo '<pre>';
//        print_r($clock);
        return json(['code'=>200,'data'=>$clock]);
    }

    /**获取考勤信息
     * @param Request $request
     * @return \think\response\Json
     */
    public function attenStatic(Request $request){
        //获取查询每日的日期
        $ryear = $request->param('ryear',date('Y',time()));
        $rmonth = $request->param('rmonth',date('m',time()));
        $rday = $request->param('rday',date('d',time()));
        //获取查询每月的日期
        $myear = $request->param('myear',date('Y',time()));
        $mmonth = $request->param('mmonth',date('m',time()));
        $token = $request->param('token',null);
        if(!$user = GetUser::get($token)){
            return returns();
        }
        $department_id = $request->param('department_id',$user['department_id']);
        $day = $ryear.'-'.$rmonth.'-'.$rday;
        $month = $myear.'-'.$mmonth;
        $a = 0;
        if($day==date('Y-m-d',time())){
            $a=1;
        }
        //获取当前部门的设置
        $setting = SettingModel::getSetting()->where('card_setting.department_id',$department_id)->find();
        //获取查询每天的开始和结束时间戳
        $day = strToDay($day);
        //获取当前部门的各个人的信息
        $users = UserModel::getIndexUser()
            ->where('user.department_id',$department_id)
            ->where('user.status',1)
            ->select();
        $days['number'] = count($users);
        $days['department'] = DepartmenModel::getDepartmen()->where('departmen_table.id',$department_id)->field('company_name,departmen_name')->find();
        $days['department'] = $days['department']['company_name'].'/'.$days['department']['departmen_name'];
        //获取某月的上班天数
        $enday = Apis::getDays($department_id,$month);
        //        //获取查询每月的开始和结束时间戳
        $month = strToMonth($month);
        $months['number'] = count($enday);
        $months['quanqing']=0;
        if(!in_array(date('w',$day['start']),$setting['attendance'])){
            $days['shanban'] = '这天不上班';
        }else{
            $days['shanban'] = '这天上班';
        }
            foreach ($users as $value){
                if(time()<$day['start']+$setting['work_shift']){
                    $days[$value['nickname']]['toWork']='未到打卡时间';
                }else{
                    $days[$value['nickname']]['toWork'] = ClockModel::getClock()
                        ->where('punch_clock.userid',$value['id'])
                        ->where('punch_clock.punch_type','toWork')
                        ->where('punch_clock.create_time','>',$day['start'])
                        ->where('punch_clock.create_time','<',$day['end'])
                        ->find();
                }
                if(time()<$day['start']+$setting['closing_time']){
                    $days[$value['nickname']]['offWork'] = '未到打卡时间';
                }else{
                    $days[$value['nickname']]['offWork'] = ClockModel::getClock()
                        ->where('punch_clock.userid',$value['id'])
                        ->where('punch_clock.punch_type','offWork')
                        ->where('punch_clock.create_time','>',$day['start'])
                        ->where('punch_clock.create_time','<',$day['end'])
                        ->find();
                }
                $datass = ClockModel::getClock()
                    ->where('punch_clock.userid',$value['id'])
                    ->where('punch_clock.create_time','>',$month['start'])
                    ->where('punch_clock.create_time','<',$month['end'])
                    ->where('punch_clock.late',1)
                    ->whereOr('punch_clock.absenteeism',1)
                    ->whereOr('punch_clock.leave',1)
                    ->whereOr('punch_clock.early_retreat',1)
                    ->count();
                if(!$datass){
                    $months['quanqing']=$months['quanqing']+1;
                }
            }


        $months['zhenc']['toWork'] = 0;
        $months['zhenc']['offWork'] = 0;
        $months['qingjia']['toWork'] = 0;
        $months['qingjia']['offWork'] = 0;
        $months['chidao']['toWork'] = 0;
        $months['zaotui']['offWork'] = 0;
        //上班打卡正常的条数
        $months['zhenc']['toWork'] = ClockModel::getClock()
            ->where('punch_clock.departmen_id',$department_id)
            ->where('punch_clock.punch_type','toWork')
            ->where('punch_clock.create_time','>',$month['start'])
            ->where('punch_clock.create_time','<',$month['end'])
            ->where('punch_clock.late',0)
            ->where('punch_clock.absenteeism',0)
            ->where('punch_clock.leave',0)
            ->count();
        //下班正常的条数
        $months['zhenc']['offWork'] = ClockModel::getClock()
            ->where('punch_clock.departmen_id',$department_id)
            ->where('punch_clock.punch_type','offWork')
            ->where('punch_clock.create_time','>',$month['start'])
            ->where('punch_clock.create_time','<',$month['end'])
            ->where('punch_clock.early_retreat',0)
            ->where('punch_clock.absenteeism',0)
            ->where('punch_clock.leave',0)
            ->count();
        //迟到的条数
        $months['chidao']['toWork'] = ClockModel::getClock()
            ->where('punch_clock.departmen_id',$department_id)
            ->where('punch_clock.punch_type','toWork')
            ->where('punch_clock.create_time','>',$month['start'])
            ->where('punch_clock.create_time','<',$month['end'])
            ->where('punch_clock.late',1)
            ->where('punch_clock.absenteeism',0)
            ->where('punch_clock.leave',0)
            ->where('punch_clock.overtime',0)
            ->count();
        //早退的条数
        $months['zaotui']['offWork'] = ClockModel::getClock()
            ->where('punch_clock.departmen_id',$department_id)
            ->where('punch_clock.punch_type','offWork')
            ->where('punch_clock.create_time','>',$month['start'])
            ->where('punch_clock.create_time','<',$month['end'])
            ->where('punch_clock.early_retreat',1)
            ->where('punch_clock.absenteeism',0)
            ->where('punch_clock.leave',0)
            ->where('punch_clock.overtime',0)
            ->count();
        //上班请假的条数
        $months['qingjia']['toWork'] = ClockModel::getClock()
            ->where('punch_clock.departmen_id',$department_id)
            ->where('punch_clock.punch_type','toWork')
            ->where('punch_clock.create_time','>',$month['start'])
            ->where('punch_clock.create_time','<',$month['end'])
            ->where('punch_clock.leave',1)
            ->count();
        //下班请假的条数
        $months['qingjia']['offWork'] = ClockModel::getClock()
            ->where('punch_clock.departmen_id',$department_id)
            ->where('punch_clock.punch_type','offWork')
            ->where('punch_clock.create_time','>',$month['start'])
            ->where('punch_clock.create_time','<',$month['end'])
            ->where('punch_clock.leave',1)
            ->count();
        $months['wei']['toWork'] = $months['number']*$days['number']-$months['qingjia']['toWork']-$months['chidao']['toWork']-$months['zhenc']['toWork'];
        $months['wei']['offWork'] = $months['number']*$days['number']-$months['qingjia']['offWork']-$months['zaotui']['offWork']-$months['zhenc']['offWork'];
//        echo '<pre>';
//        print_r($months);exit;
        return json(['code'=>200,'days'=>$days,'months'=>$months]);
    }

    /**获取本公司的部门列表
     * @param Request $request
     * @return \think\response\Json
     */
    public function departmenList(Request $request){
        $token = $request->param('token',null);
//        return json(['code'=>$token]);
        if(!$user = GetUser::get($token)){
            return returns();
        }
        $data = DepartmenModel::getDepartmen()
            ->where('departmen_table.company_id',$user['company_id'])
            ->select();
        return json(['code'=>200,'data'=>$data]);
    }
    /**获取本公司的部门列表和人员列表
     * @param Request $request
     * @return \think\response\Json
     */
    public function getPersonnel(Request $request){
        $token = $request->param('token',null);
        if(!$user = GetUser::get($token)){
            return returns();
        }
        $department = DepartmenModel::getDepartmen()
            ->where('departmen_table.company_id',$user['company_id'])
            ->select();
        $data = [];
        foreach ($department as $key=>$value){
            $data[$value['departmen_name']] = UserModel::getIndexUser()
                ->where('user.department_id',$value['id'])
                ->select();
        }
        return json(['code'=>200,'data'=>$data]);
    }
    /**请假
     * @param Request $request
     * @return \think\response\Json
     */
    public function leave(Request $request){
        $data = $request->param();
        $val = val($data,[
            'token|登陆码'=>'require',
            'approver_id|审核人'=>'require',
            'reason|请假理由'   =>'require',
        ]);
        if(!$val['code']){
            return returns(205,$val['msg']);
        }
        if(!$user = GetUser::get($data['token'])){
            return returns();
        }
        //获取的数据处理
        $data['starttime'] = strtotime($data['starttime']);
        $data['endtime'] = strtotime($data['endtime']);
        if(!$data['reason']||$data['reason']==' '){
            return returns(402,'请填写请假理由');
        }
        $data['time'] = time();
        $data['userid'] = $user['id'];
        $data['company_id'] = $user['company_id'];
        $data['departmen_id'] = $user['department_id'];
        $data['status'] = 0;
        $file = UpFile::getFile($request);
        if($file){
            foreach ($file as $value){
                $data['leave_picture'][] = $value;
            }
        }
        unset($data['token']);
//        echo '<pre>';
//        print_r($data);exit;
//        return returns(201,$data['status']);
//        return LeaveModel::addLeaveGetId($data);
        //消息添加
        $news['receive_id'] = $data['approver_id'];
        $news['send_out'] = $user['id'];
        $news['news_type'] = 'leave';
        $news['describe'] = $user['nickname'].'的请假条';
        $news['cretae_time'] = time();
        $news['status'] = 0;
//        echo '<pre>';
//        print_r($news);exit;
        //添加请假条并获取所在id
        $bool = LeaveModel::addLeaveGetId($data);
//                echo '<pre>';
//        print_r($bool);exit;
        if($bool){
            $news['table_id'] = $bool;
        }else{
            return returns(405,'添加假条失败');
        }
        //添加消息
        if(Db::name('news')->insert($news)){
            return returns(200,'提交请假条成功');
        }else{
            return returns(408,'提交请假条失败');
        }
    }
    /**添加报告
     * @param Request $request
     * @return \think\response\Json
     */
    public function report(Request $request){
        $data = $request->param();
        $val = val($data,[
            'token' =>'require',
            'work_report_type|报告类型'=>'require',
            'work_report_title|报告标题'=>'require',
            'recipient|接收人'          =>'require',
            'contents|报告内容'         =>'require'
        ]);
        if(!$val['code']){
            return returns(204,$val['msg']);
        }
        if(!$user = GetUser::get($data['token'])){
            return returns();
        }
        unset($data['token']);
        $data['author'] = $user['id'];
        $data['company_id'] = $user['company_id'];
        $data['department_id'] = $user['department_id'];
        $data['create_time'] = time();
        if($filename = UpFile::getFile($request)){
            foreach ($filename as $value){
                $data['picture'][] = $value;
            }
        }
//        echo '<pre>';
//        print_r($data);exit;
        //填写消息数据
        $news['receive_id'] = $data['recipient'];
        $news['send_out']   = $user['id'];
        $news['news_type']  = 'work_report';
        if($data['work_report_type']==1){
            $news['describe'] = $user['nickname'].'的工作日报';
        }elseif ($data['work_report_type']==2){
            $news['describe'] = $user['nickname'].'的工作周报';
        }elseif ($data['work_report_type']==3){
            $news['describe'] = $user['nickname'].'的工作月报';
        }
        $news['cretae_time'] = time();
        $news['status']      = 0;
        $bool = ReportModel::addReportGetId($data);
        if($bool){
            $news['table_id'] = $bool;
        }else{
            return returns(406,'添加报告失败');
        }
        if(Db::name('news')->insert($news)){
            return returns(200,'添加报告成功');
        }else{
            return returns(508,'添加报告失败');
        }
    }
}